package com.atguigu.juc.locks;


import java.util.concurrent.TimeUnit;

//同一部手机两个synchronized锁方法，发其中一个暂停2秒
class Phone2{
    public synchronized void sengEmail(){
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "正在发邮件...");
    }
    public synchronized void sengSMS(){
        System.out.println(Thread.currentThread().getName() + "正在发短信...");
    }
}

public class Lock8_2 {
    public static void main(String[] args) {
        Phone2 phone2 = new Phone2();

        new Thread(()->{phone2.sengEmail();},"t1").start();

        try {
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{phone2.sengSMS();},"t2").start();
    }
}
